package com.yh.correct.service.impl;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yh.correct.dao.IHelpMapper;
import com.yh.correct.model.Help;
import com.yh.correct.model.Page;
import com.yh.correct.service.IHelpService;
/**
 * 帮困解难service层实现类
 * @author Administrator
 *
 */
@Service
public class HelpServiceImpl implements IHelpService{
	/**
	 * 日志
	 */
	private static Logger logger=LogManager.getLogger(HelpServiceImpl.class);
	/**
	 * 帮困解难DAO数据接口
	 */
	@Autowired
	private IHelpMapper HelpMapper;
	/**
	 * 查询单个帮困解难记录
	 */
	@Override
	public Help getEudcation_Help(Help Help) {
		// TODO Auto-generated method stub
		return HelpMapper.gethelp(Help);
	}
	/**
	 * 删除帮困解难记录
	 */
	@Override
	public int delHelp(Help Help) {
		return HelpMapper.addhelp(Help);
	}
	/**
	 * 修改帮困解难记录
	 */
	@Override
	public int editHelp(Help Help) {
		return HelpMapper.edithelp(Help);
	}
	/**
	 * 增加帮困解难记录
	 */
	@Override
	public int addHelp(Help Help) {
		return HelpMapper.addhelp(Help);
	}
	/**
	 * 动态模糊查询帮困解难记录
	 */
	@Override
	public Page queryLikeHelp(Map<String, Object> condition) {
		// TODO Auto-generated method stub
		Page page=new Page();
		//根据条件查询符合的用户列表记录总数，赋值给page的totalNum变量
		page.setTotalNum(HelpMapper.getLikehelpsCount(condition));
		//从请求参数中获取每页大小
		int pageSize = Integer.parseInt(String.valueOf(condition.get("pageSize")));
		page.setPageSize(pageSize);
		//从请求参数中获取当前页码
		int curPageNum = Integer.parseInt(String.valueOf(condition.get("pageNum")));
		page.setCurPageNum(curPageNum);
		//动态计算总页数(总记录数 除以 每页大小，加上  总页数 求余 每页大小，如果余数不为0，则 加 1，否则 加 0 )
		page.setTotalNum(page.getTotalNum()/pageSize+(page.getTotalNum()%pageSize==0?0:1));
		//根据条件查询符合的用户列表记录，赋值给page的result变量
		page.setResult(HelpMapper.getLikhelps(condition));
		return page;
	}
}
